<template>
    <div class="page has-navbar index" v-nav="{hideNavbar: true}" v-tabbar="{'menus': menus, menuColor: '#B5B5B5', activeMenuColor: '#ffd400', onMenuClick: menuClicked}">
        <router-view :openId="openId" :returnUrl="returnUrl"></router-view>
    </div>
</template>

<script>
import {API_BASE_URL} from "./../../urlConfig/index";
export default {
    data(){
        return {
            menus: [
                {
                    iconOn: 'ion-ios-pricetags',
                    iconOff: 'ion-ios-pricetags-outline',
                    text: '优惠券',
                    path: '/index/coupon'
                },
                {
                    iconOn: 'ion-ios-recording',
                    iconOff: 'ion-ios-recording-outline',
                    text: '店铺',
                    path: '/index/store',
                },
                {
                    iconOn: 'ion-ios-list',
                    iconOff: 'ion-ios-list-outline',
                    text: '消费记录',
                    path: '/index/order'
                },
                {
                    iconOn: 'ion-ios-person',
                    iconOff: 'ion-ios-person-outline',
                    text: '我的',
                    path: '/index/my',
                },
            ],
            openId: '',
            returnUrl:''
        }
    },
    methods:{
        menuClicked(menuIndex) {
            console.log(menuIndex);
        }
    },
    created(){
        let searchStr = window.location.search.split('?')[1];
        let searchArr = searchStr.split('&');
        let searchObj = {};
        for (var i = 0; i < searchArr.length; i++) {
            var curParam = searchArr[i].split('=');
            searchObj[curParam[0]] = curParam[1];
        }
        this.openId = searchObj.openId;
    },
    mounted(){
        let url =  window.location.href.split("#")[0];
        this.$http.get(API_BASE_URL+'wechat/signature?url='+url).then((res)=>{
            this.returnUrl = res.data.url
            wx.config({
                debug: false,
                appId: res.data.appId,
                timestamp: res.data.timestamp,
                nonceStr: res.data.nonceStr,
                signature: res.data.signature,
                jsApiList: [
                    'checkJsApi',
                    'onMenuShareTimeline',
                    'onMenuShareAppMessage',
                    'onMenuShareQQ',
                    'onMenuShareWeibo',
                    'onMenuShareQZone'
                ]
            });
        })
    },
    beforeDestroy() {
        $tabbar.$emit('hideTabbar')
    },
}
</script>
<style lang="scss" scoped>
    @import "index";
</style>
